package com.macro.mall.tiny.modules.oms.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.macro.mall.tiny.component.wx.entity.bo.WxPayBO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * <p>
 * 订单表
 * </p>
 *
 * @author tyrone
 * @since 2024-10-25
 */
@Getter
@Setter
@TableName("oms_order")
@ApiModel(value = "OmsOrder对象", description = "订单表")
public class OmsOrder implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("主键id")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty("订单id")
    private String orderId;

    @ApiModelProperty("商品id(目前只有：会员计划)")
    private Integer goodId;

    @ApiModelProperty("订单支付者openId")
    private String openId;

    @ApiModelProperty("订单状态 0待支付 1已支付 2支付失败 3已失效")
    private Integer status;

    @ApiModelProperty("订单创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @ApiModelProperty("订单支付时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date payTime;

    @ApiModelProperty("总费用（单位分）")
    private Integer totalFee;

    @ApiModelProperty("实际费用（单位分）")
    private Integer actualFee;

    @ApiModelProperty("优惠码")
    private String promoCode;


    @TableField(exist = false)
    @ApiModelProperty("商品列表")
    private List<OmsGood> goods;



    public WxPayBO buildWxPayBO() {
        WxPayBO wxPayBO = new WxPayBO();
        wxPayBO.setOpenId(this.openId);
        wxPayBO.setInnerOrderNo(this.orderId);
        wxPayBO.setTotal(this.actualFee);
        //todo 通过goodId获取描述或者是名称
        wxPayBO.setDesc(WxPayBO.DescEnum.getDescEnum(this.goodId));
        return wxPayBO;
    }



}
